<?php
// [登录控制器]
class LoginController extends Controller{

    public function index(){
        if(IS_POST){
            $model = K('User');
            //验证登录
            if($userInfo = $model->validate_login()){
                //写入session信息
                session('aid',$userInfo['uid']);
                session('adminname',$userInfo['username']);
                //提示信息
                $this->success('登录成功',U('Index/index'));
            }
            $this->error($model->error);
        }
        if(session('aid') && session('adminname')){
            go(U('Index/index'));
        }
        $this->display();
    }

   // [code 显示验证码]
    public function code(){
        $code = new Code();
        $code->show();
    }

    // [out 退出登录]
    public function out(){
        session(NULL);
        $this->success('退出成功',U('Login/index'));
    }   
}
?>